#include    <antlr3.h>
#include <stdio.h>
#include "GraphicsLexer.h"
#include "GraphicsParser.h"

int main(int argc, char *argv[])
{
    pANTLR3_INPUT_STREAM input = NULL;
    
    if (argc == 2) {
        pANTLR3_UINT8 fName;
        fName = (pANTLR3_UINT8)argv[1];
        input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);
    }
    if (input == NULL) {
        exit(1);
    }
    pGraphicsLexer lex = GraphicsLexerNew(input);
    pANTLR3_COMMON_TOKEN_STREAM tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT,
                                                                          TOKENSOURCE(lex));
    pGraphicsParser p = GraphicsParserNew(tokens);

    p->file(p);

    if (p->pParser->rec->state->errorCount > 0)
	{
		fprintf(stderr, "The parser returned %d errors, tree walking aborted.\n", p->pParser->rec->state->errorCount);
	}
    
    p->free(p);
    tokens->free(tokens);
    lex->free(lex);
    input->close(input);
    exit(0);
}
